package com.jisuan.contract.controller;

import java.util.Arrays;
import java.util.Map;


import com.jisuan.contract.entity.ContractEntity;
import com.jisuan.contract.service.ContractService;
import com.jisuan.contract.utils.PageUtils;
import com.jisuan.contract.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 合同表
 *
 * @author wangdajun
 * @email wangdajunzy@163.com
 * @date 2021-12-27 14:04:13
 */
@RestController
@RequestMapping("contract/contract")
public class ContractController {
    @Autowired
    private ContractService contractService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = contractService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		ContractEntity contract = contractService.getById(id);

        return R.ok().put("contract", contract);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ContractEntity contract){
        System.out.println("保存合同");
        System.out.println(contract);
		contractService.save(contract);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ContractEntity contract){
		contractService.updateById(contract);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		contractService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
